package com.woniuxy.dr_mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.dr_mall.entity.DrComment;
import com.woniuxy.dr_mall.entity.DrCommentInfo;
import com.woniuxy.dr_mall.entity.DrUser;
import com.woniuxy.dr_mall.mapper.DrCommentMapper;
import com.woniuxy.dr_mall.mapper.DrPictureMapper;
import com.woniuxy.dr_mall.mapper.DrUserMapper;
import com.woniuxy.dr_mall.service.IDrCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
@Service
public class DrCommentServiceImpl extends ServiceImpl<DrCommentMapper, DrComment> implements IDrCommentService {

    @Autowired
    private DrCommentMapper drCommentMapper;

    @Autowired
    private DrPictureMapper drPictureMapper;

    @Autowired
    private DrUserMapper drUserMapper;

    @Override
    public List<DrCommentInfo> getNotComment(Integer userId) {
        return drCommentMapper.getNotComment(userId);
    }

    @Override
    public List<DrComment> getCommentByUserId(Integer userId) {
        return drCommentMapper.getCommentByUserId(userId);
    }

    @Override
    public void delById(Integer id) {
        drCommentMapper.delById(id);
    }

    @Override
    public void add(DrComment drComment) {
        drCommentMapper.add(drComment);
    }

    @Override
    public int getNotCommentCount(int userId) {
        return drCommentMapper.getNotCommentCount(userId);
    }

    @Override
    public List<DrComment> getProductCommentByPId(int pid) {
        List<DrComment> list = drCommentMapper.getProductCommentByPId(pid);
        list.forEach(e->{
            e.setDrUser(drUserMapper.getById(e.getUserId()));
            e.setProductCommentImages(drPictureMapper.getCommentImagesByCId(e.getId()));
        });
        return list;
    }


}
